home *** CD-ROM | disk | FTP | other *** search
- From: lenny@icus.UUCP (Lenny Tropiano)
- Newsgroups: comp.sources.misc
- Subject: v02i024: sysinfo: display system info on window (UNIX PC only)
- Message-ID: <7138@ncoast.UUCP>
- Date: 28 Jan 88 00:36:48 GMT
- Approved: allbery@ncoast.UUCP
-
- Comp.sources.misc: Volume 2, Issue 24
- Submitted-By: Lenny Tropiano <lenny@icus.UUCP>
- Archive-Name: sysinfo
-
- [WARNING!!! I see a bug in the Makefile. The "install" commands do chown/
- chgrp/chmod on the DIRECTORY, not the file. Fix it before you use it. ++bsa]
-
- Here's a little ditty I wrote:
-
- --- cut here --- --- cut here --- --- cut here --- --- cut here ---
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of shell archive."
- # Contents: README Makefile sysinfo.c
- # Wrapped by lenny@icus.UUCP on Sun Jan 24 01:13:20 EST 1988
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f README -a "${1}" != "-c" ; then
- echo shar: Will not over-write existing file \"README\"
- else
- echo shar: Extracting \"README\" \(1842 characters\)
- sed "s/^X//" >README <<'END_OF_README'
- XI wrote this little ditty just to utilize the two lines on the bottom of
- Xthe screen where the soft labels for the function keys are normally displayed.
- XThis program will only work if you login on the console (obviously) and
- Xyou aren't using the "user agent" or something that needs those two lines.
- X
- XI give thanks to Scott Hazen Mueller for his contribution of "newmgr.c"
- Xthat initially gave me the idea for displaying the file system information.
- X
- XAfter unpacking the shar file, "su" and become root. Then type:
- X
- X # make install
- X
- XThis will copy the program into /usr/lbin (as defined by the Makefile) but
- Xyou might just want to have this for your own "bin" directory, because
- Xit is only useful if you run on a windowed device.
- X
- XThe mail file is only read for the number of messages if the modification
- Xtime changes since the last read (saving on disk I/O). This program also
- Xruns with a nice value of 5, and sleeps for 15 seconds between passes.
- X(#defined by NICE and SLEEP respectively)
- X
- XYou might want to place the following lines in your /etc/localprofile
- Xor .profile to activate sysinfo apon login:
- X
- XTTY=`tty`
- Xif [ "`expr $TTY : '/dev/w' `" != "0" ]
- Xthen
- X sysinfo
- Xfi
- X
- XPlease report any bugs, suggestions and problems to me:
- X
- X============================ US MAIL: Lenny Tropiano, ICUS Computer Group
- X IIIII CCC U U SSSS PO Box 1
- X I C C U U S Islip Terrace, New York 11752
- X I C U U SSS PHONE: (516) 968-8576 [H] (516) 582-5525 [W]
- X I C C U U S AT&T MAIL: ...attmail!icus!lenny TELEX: 154232428
- X IIIII CCC UUU SSSS UUCP:
- X============================ ...{uunet!godfre, harvard!talcott}!\
- X ...{ihnp4, boulder, mtune, bc-cis, ptsfa, sbcs}! >icus!lenny
- X"Usenet the final frontier" ...{cmcl2!phri, hoptoad}!dasys1!/
- END_OF_README
- if test 1842 -ne `wc -c <README`; then
- echo shar: \"README\" unpacked with wrong size!
- fi
- # end of overwriting check
- fi
- if test -f Makefile -a "${1}" != "-c" ; then
- echo shar: Will not over-write existing file \"Makefile\"
- else
- echo shar: Extracting \"Makefile\" \(474 characters\)
- sed "s/^X//" >Makefile <<'END_OF_Makefile'
- X#
- X# Makefile to compile sysinfo.c (System Info)
- X# By Lenny Tropiano
- X# (c)1987 ICUS Computer Group UUCP: ...icus!lenny
- X#
- XCFLAGS=-v -O
- XLDFLAGS=-s
- XLIBS=/lib/crt0s.o /lib/shlib.ifile
- XDEST=/usr/lbin/
- X#
- Xsysinfo.o:
- X $(CC) $(CFLAGS) -c sysinfo.c
- X#
- Xsysinfo: sysinfo.o
- X @echo "Loading ..."
- X $(LD) $(LDFLAGS) $(LIBS) sysinfo.o -o sysinfo
- X#
- X# You need to be superuser to do this
- X#
- Xinstall: sysinfo
- X cp sysinfo $(DEST)
- X chown root $(DEST)
- X chgrp bin $(DEST)
- X chmod 4750 $(DEST)
- END_OF_Makefile
- if test 474 -ne `wc -c <Makefile`; then
- echo shar: \"Makefile\" unpacked with wrong size!
- fi
- # end of overwriting check
- fi
- if test -f sysinfo.c -a "${1}" != "-c" ; then
- echo shar: Will not over-write existing file \"sysinfo.c\"
- else
- echo shar: Extracting \"sysinfo.c\" \(5681 characters\)
- sed "s/^X//" >sysinfo.c <<'END_OF_sysinfo'
- X/************************************************************************\
- X** **
- X** Program name: sysinfo.c (System Info) **
- X** Programmer: Lenny Tropiano UUCP: ...icus!lenny **
- X** Organization: ICUS Computer Group (c)1988 **
- X** Date: January 23, 1988 **
- X** **
- X**************************************************************************
- X** **
- X** Credits: The idea of displaying the file system information **
- X** came from Scott Hazen Mueller's newmgr, the replace- **
- X** ment to the smgr. **
- X** **
- X**************************************************************************
- X** **
- X** Program use: Program is run as a info process from your .profile **
- X** This program the file system and displays the **
- X** pertinent information on the bottom of the screen **
- X** where the software labels would normally be displayed. **
- X** The program also displays the uptime. **
- X** **
- X**************************************************************************
- X** Permission is granted to distribute this program by any means as **
- X** long as credit is given for my work. I would also like to see **
- X** any modifications or enhancements to this program. **
- X\************************************************************************/
- X
- X#include <stdio.h>
- X#include <fcntl.h>
- X#include <errno.h>
- X#include <signal.h>
- X#include <sys/types.h>
- X#include <sys/stat.h>
- X#include <sys/window.h>
- X#include <sys/filsys.h>
- X#include <utmp.h>
- X
- X#define MINUTE 60L
- X#define HOUR (60L * 60L)
- X#define DAY (24L * 60L * 60L)
- X#define SLEEP 15 /* Sleep time (interval between)*/
- X#define NICE 5 /* Niceness value */
- X
- X#define LINE_1 "%-40.40s up %2d day%1.1s %2d hour%1.1s %2d minute%1.1s"
- X#define LINE_2 "Filesystem (%-5.5s) %6ld free %6ld total blocks %2d%% available %5d i-nodes"
- X#define FILESYS "/dev/rfp002"
- X#define FNAME "fp002"
- X#ifndef TRUE
- X#define TRUE 1
- X#endif
- X
- Xchar *progname; /* program name */
- Xchar mailfile[30]; /* mailbox file name */
- Xstruct utdata utd; /* Window data structure */
- Xstruct filsys fs; /* Filesystem superblock struct */
- Xtime_t boottime; /* system boot time in sec */
- Xtime_t mailtime = 0L; /* mail modification time */
- Xint msgs = 0;
- Xunsigned long days = 0L;
- Xunsigned long hrs = 0L;
- Xunsigned long mins = 0L;
- X
- X/************************************************************************/
- X
- Xmain(argc,argv)
- Xint argc;
- Xchar *argv[];
- X{
- X int terminate();
- X char *getenv();
- X struct utmp *utent, *getutent();
- X
- X if (fork() != 0) /* detach process-info */
- X exit(0);
- X
- X nice(NICE); /* Be a little nice */
- X signal (SIGINT, SIG_IGN);
- X signal (SIGQUIT, SIG_IGN);
- X signal (SIGHUP, terminate);
- X signal (SIGTERM, terminate);
- X
- X progname = *argv;
- X sprintf(mailfile,"%s",getenv("MAIL"));
- X
- X setutent();
- X while ((utent = getutent()) != (struct utmp *)NULL) {
- X if (utent->ut_type == BOOT_TIME) {
- X boottime = utent->ut_time;
- X break;
- X }
- X }
- X endutent();
- X
- X info_process();
- X terminate();
- X
- X}
- X
- Xinfo_process()
- X{
- X char mailbuffer[40];
- X
- X while (TRUE) {
- X filestatus();
- X uptime();
- X mailcheck(mailbuffer);
- X
- X utd.ut_num = WTXTSLK1;
- X sprintf(utd.ut_text,LINE_1,
- X mailbuffer,
- X days,(days == 1) ? " " : "s",
- X hrs, (hrs == 1) ? " " : "s",
- X mins,(mins == 1) ? " " : "s"
- X );
- X ioctl(0, WIOCSETTEXT, &utd);
- X
- X utd.ut_num = WTXTSLK2;
- X sprintf(utd.ut_text,LINE_2,
- X FNAME, fs.s_tfree * 2, fs.s_fsize * 2,
- X (int)((((float)fs.s_tfree / (float)fs.s_fsize) + 0.005)
- X * 100.0), fs.s_tinode
- X );
- X ioctl(0, WIOCSETTEXT, &utd);
- X
- X sleep(SLEEP);
- X }
- X}
- X
- Xint terminate()
- X{
- X utd.ut_num = WTXTSLK1; /* clear the label area */
- X utd.ut_text[0] = '\0';
- X ioctl(0, WIOCSETTEXT, &utd);
- X utd.ut_num = WTXTSLK2;
- X ioctl(0, WIOCSETTEXT, &utd);
- X
- X exit(0);
- X}
- X
- Xfilestatus()
- X{
- X int fd;
- X
- X if ((fd = open(FILESYS, O_RDONLY)) == -1) {
- X fprintf(stderr,"%s: cannot open %s for read\n",
- X progname, FILESYS);
- X terminate();
- X }
- X
- X if (lseek(fd, 512, 0) == -1) {
- X fprintf(stderr,"%s: cannot lseek to superblock\n", progname);
- X terminate();
- X }
- X
- X if (read(fd, &fs, sizeof(struct filsys)) == -1) {
- X fprintf(stderr,"%s: cannot read the superblock\n", progname);
- X terminate();
- X }
- X
- X close(fd);
- X
- X}
- X
- Xuptime()
- X{
- X time_t curtime, bootsec;
- X
- X time(&curtime);
- X bootsec = curtime - boottime;
- X
- X days = bootsec / DAY;
- X bootsec -= DAY * days;
- X hrs = bootsec / HOUR;
- X bootsec -= HOUR * hrs;
- X mins = bootsec / MINUTE;
- X bootsec -= MINUTE * mins;
- X}
- X
- Xmailcheck(buf)
- Xchar *buf;
- X{
- X FILE *fp;
- X char buffer[BUFSIZ];
- X struct stat statbuf;
- X
- X if (access(mailfile,4) == 0) {
- X if (stat(mailfile,&statbuf) != -1) {
- X if (statbuf.st_ctime > mailtime) {
- X msgs = 0;
- X if ((fp = fopen(mailfile,"r")) != NULL) {
- X while (fgets(buffer, BUFSIZ, fp) != NULL)
- X if (strncmp(buffer,"From ",5) == 0)
- X msgs++;
- X }
- X fclose(fp);
- X mailtime = statbuf.st_ctime;
- X }
- X }
- X }
- X if (msgs)
- X sprintf(buf,"%d mail message%s in your mailbox",msgs,
- X (msgs == 1) ? "" : "s");
- X else
- X buf[0] = '\0';
- X}
- END_OF_sysinfo
- fi
- if test 5681 -ne `wc -c <sysinfo.c`; then
- echo shar: \"sysinfo.c\" unpacked with wrong size!
- fi
- # end of overwriting check
- echo shar: End of shell archive.
- exit 0
- --
- ============================ US MAIL: Lenny Tropiano, ICUS Computer Group
- IIIII CCC U U SSSS PO Box 1
- I C C U U S Islip Terrace, New York 11752
- I C U U SSS PHONE: (516) 968-8576 [H] (516) 582-5525 [W]
- I C C U U S AT&T MAIL: ...attmail!icus!lenny TELEX: 154232428
- IIIII CCC UUU SSSS UUCP:
- ============================ ...{uunet!godfre, harvard!talcott}!\
- ...{ihnp4, boulder, mtune, bc-cis, ptsfa, sbcs}! >icus!lenny
- "Usenet the final frontier" ...{cmcl2!phri, hoptoad}!dasys1!/
-